Passed
Pull Request — master (#47)
by
unknown
05:23
created

tooltip.js ➔ _interopDefaultLegacy   B

Complexity

Conditions 7

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 1
dl 0
loc 1
rs 8
c 0
b 0
f 0
1
/*!
2
  * Bootstrap tooltip.js v4.6.0 (https://getbootstrap.com/)
3
  * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
4
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5
  */
6
(function (global, factory) {
7
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('popper.js'), require('./util.js')) :
8
  typeof define === 'function' && define.amd ? define(['jquery', 'popper.js', './util'], factory) :
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
9
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Tooltip = factory(global.jQuery, global.Popper, global.Util));
0 ignored issues
show
Bug introduced by
The variable globalThis seems to be never declared. If this is a global, consider adding a /** global: globalThis */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Best Practice introduced by
If you intend to check if the variable self is declared in the current environment, consider using typeof self === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10
}(this, (function ($, Popper, Util) { 'use strict';
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
14
  var $__default = /*#__PURE__*/_interopDefaultLegacy($);
15
  var Popper__default = /*#__PURE__*/_interopDefaultLegacy(Popper);
16
  var Util__default = /*#__PURE__*/_interopDefaultLegacy(Util);
17
18
  function _defineProperties(target, props) {
19
    for (var i = 0; i < props.length; i++) {
20
      var descriptor = props[i];
21
      descriptor.enumerable = descriptor.enumerable || false;
22
      descriptor.configurable = true;
23
      if ("value" in descriptor) descriptor.writable = true;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
24
      Object.defineProperty(target, descriptor.key, descriptor);
25
    }
26
  }
27
28
  function _createClass(Constructor, protoProps, staticProps) {
29
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
30
    if (staticProps) _defineProperties(Constructor, staticProps);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
31
    return Constructor;
32
  }
33
34
  function _extends() {
35
    _extends = Object.assign || function (target) {
0 ignored issues
show
Comprehensibility introduced by
It seems like you are trying to overwrite a function name here. _extends is already defined in line 34 as a function. While this will work, it can be very confusing.
Loading history...
36
      for (var i = 1; i < arguments.length; i++) {
37
        var source = arguments[i];
38
39
        for (var key in source) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
40
          if (Object.prototype.hasOwnProperty.call(source, key)) {
41
            target[key] = source[key];
42
          }
43
        }
44
      }
45
46
      return target;
47
    };
48
49
    return _extends.apply(this, arguments);
50
  }
51
52
  /**
53
   * --------------------------------------------------------------------------
54
   * Bootstrap (v4.6.0): tools/sanitizer.js
55
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
56
   * --------------------------------------------------------------------------
57
   */
58
  var uriAttrs = ['background', 'cite', 'href', 'itemtype', 'longdesc', 'poster', 'src', 'xlink:href'];
59
  var ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i;
60
  var DefaultWhitelist = {
61
    // Global attributes allowed on any supplied element below.
62
    '*': ['class', 'dir', 'id', 'lang', 'role', ARIA_ATTRIBUTE_PATTERN],
63
    a: ['target', 'href', 'title', 'rel'],
64
    area: [],
65
    b: [],
66
    br: [],
67
    col: [],
68
    code: [],
69
    div: [],
70
    em: [],
71
    hr: [],
72
    h1: [],
73
    h2: [],
74
    h3: [],
75
    h4: [],
76
    h5: [],
77
    h6: [],
78
    i: [],
79
    img: ['src', 'srcset', 'alt', 'title', 'width', 'height'],
80
    li: [],
81
    ol: [],
82
    p: [],
83
    pre: [],
84
    s: [],
85
    small: [],
86
    span: [],
87
    sub: [],
88
    sup: [],
89
    strong: [],
90
    u: [],
91
    ul: []
92
  };
93
  /**
94
   * A pattern that recognizes a commonly useful subset of URLs that are safe.
95
   *
96
   * Shoutout to Angular 7 https://github.com/angular/angular/blob/7.2.4/packages/core/src/sanitization/url_sanitizer.ts
97
   */
98
99
  var SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file):|[^#&/:?]*(?:[#/?]|$))/gi;
100
  /**
101
   * A pattern that matches safe data URLs. Only matches image, video and audio types.
102
   *
103
   * Shoutout to Angular 7 https://github.com/angular/angular/blob/7.2.4/packages/core/src/sanitization/url_sanitizer.ts
104
   */
105
106
  var DATA_URL_PATTERN = /^data:(?:image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\/(?:mpeg|mp4|ogg|webm)|audio\/(?:mp3|oga|ogg|opus));base64,[\d+/a-z]+=*$/i;
107
108
  function allowedAttribute(attr, allowedAttributeList) {
109
    var attrName = attr.nodeName.toLowerCase();
110
111
    if (allowedAttributeList.indexOf(attrName) !== -1) {
112
      if (uriAttrs.indexOf(attrName) !== -1) {
113
        return Boolean(attr.nodeValue.match(SAFE_URL_PATTERN) || attr.nodeValue.match(DATA_URL_PATTERN));
114
      }
115
116
      return true;
117
    }
118
119
    var regExp = allowedAttributeList.filter(function (attrRegex) {
120
      return attrRegex instanceof RegExp;
121
    }); // Check if a regular expression validates the attribute.
122
123
    for (var i = 0, len = regExp.length; i < len; i++) {
124
      if (attrName.match(regExp[i])) {
125
        return true;
126
      }
127
    }
128
129
    return false;
130
  }
131
132
  function sanitizeHtml(unsafeHtml, whiteList, sanitizeFn) {
133
    if (unsafeHtml.length === 0) {
134
      return unsafeHtml;
135
    }
136
137
    if (sanitizeFn && typeof sanitizeFn === 'function') {
138
      return sanitizeFn(unsafeHtml);
139
    }
140
141
    var domParser = new window.DOMParser();
142
    var createdDocument = domParser.parseFromString(unsafeHtml, 'text/html');
143
    var whitelistKeys = Object.keys(whiteList);
144
    var elements = [].slice.call(createdDocument.body.querySelectorAll('*'));
145
146
    var _loop = function _loop(i, len) {
0 ignored issues
show
Unused Code introduced by
The parameter len is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
147
      var el = elements[i];
148
      var elName = el.nodeName.toLowerCase();
149
150
      if (whitelistKeys.indexOf(el.nodeName.toLowerCase()) === -1) {
151
        el.parentNode.removeChild(el);
152
        return "continue";
153
      }
154
155
      var attributeList = [].slice.call(el.attributes);
156
      var whitelistedAttributes = [].concat(whiteList['*'] || [], whiteList[elName] || []);
157
      attributeList.forEach(function (attr) {
158
        if (!allowedAttribute(attr, whitelistedAttributes)) {
159
          el.removeAttribute(attr.nodeName);
160
        }
161
      });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
162
    };
163
164
    for (var i = 0, len = elements.length; i < len; i++) {
165
      var _ret = _loop(i);
166
167
      if (_ret === "continue") continue;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Unused Code introduced by
This continue has no effect on the loop flow and can be removed.
Loading history...
168
    }
169
170
    return createdDocument.body.innerHTML;
171
  }
172
173
  /**
174
   * ------------------------------------------------------------------------
175
   * Constants
176
   * ------------------------------------------------------------------------
177
   */
178
179
  var NAME = 'tooltip';
180
  var VERSION = '4.6.0';
181
  var DATA_KEY = 'bs.tooltip';
182
  var EVENT_KEY = "." + DATA_KEY;
183
  var JQUERY_NO_CONFLICT = $__default['default'].fn[NAME];
184
  var CLASS_PREFIX = 'bs-tooltip';
185
  var BSCLS_PREFIX_REGEX = new RegExp("(^|\\s)" + CLASS_PREFIX + "\\S+", 'g');
186
  var DISALLOWED_ATTRIBUTES = ['sanitize', 'whiteList', 'sanitizeFn'];
187
  var DefaultType = {
188
    animation: 'boolean',
189
    template: 'string',
190
    title: '(string|element|function)',
191
    trigger: 'string',
192
    delay: '(number|object)',
193
    html: 'boolean',
194
    selector: '(string|boolean)',
195
    placement: '(string|function)',
196
    offset: '(number|string|function)',
197
    container: '(string|element|boolean)',
198
    fallbackPlacement: '(string|array)',
199
    boundary: '(string|element)',
200
    customClass: '(string|function)',
201
    sanitize: 'boolean',
202
    sanitizeFn: '(null|function)',
203
    whiteList: 'object',
204
    popperConfig: '(null|object)'
205
  };
206
  var AttachmentMap = {
207
    AUTO: 'auto',
208
    TOP: 'top',
209
    RIGHT: 'right',
210
    BOTTOM: 'bottom',
211
    LEFT: 'left'
212
  };
213
  var Default = {
214
    animation: true,
215
    template: '<div class="tooltip" role="tooltip">' + '<div class="arrow"></div>' + '<div class="tooltip-inner"></div></div>',
216
    trigger: 'hover focus',
217
    title: '',
218
    delay: 0,
219
    html: false,
220
    selector: false,
221
    placement: 'top',
222
    offset: 0,
223
    container: false,
224
    fallbackPlacement: 'flip',
225
    boundary: 'scrollParent',
226
    customClass: '',
227
    sanitize: true,
228
    sanitizeFn: null,
229
    whiteList: DefaultWhitelist,
230
    popperConfig: null
231
  };
232
  var HOVER_STATE_SHOW = 'show';
233
  var HOVER_STATE_OUT = 'out';
234
  var Event = {
235
    HIDE: "hide" + EVENT_KEY,
236
    HIDDEN: "hidden" + EVENT_KEY,
237
    SHOW: "show" + EVENT_KEY,
238
    SHOWN: "shown" + EVENT_KEY,
239
    INSERTED: "inserted" + EVENT_KEY,
240
    CLICK: "click" + EVENT_KEY,
241
    FOCUSIN: "focusin" + EVENT_KEY,
242
    FOCUSOUT: "focusout" + EVENT_KEY,
243
    MOUSEENTER: "mouseenter" + EVENT_KEY,
244
    MOUSELEAVE: "mouseleave" + EVENT_KEY
245
  };
246
  var CLASS_NAME_FADE = 'fade';
247
  var CLASS_NAME_SHOW = 'show';
248
  var SELECTOR_TOOLTIP_INNER = '.tooltip-inner';
249
  var SELECTOR_ARROW = '.arrow';
250
  var TRIGGER_HOVER = 'hover';
251
  var TRIGGER_FOCUS = 'focus';
252
  var TRIGGER_CLICK = 'click';
253
  var TRIGGER_MANUAL = 'manual';
254
  /**
255
   * ------------------------------------------------------------------------
256
   * Class Definition
257
   * ------------------------------------------------------------------------
258
   */
259
260
  var Tooltip = /*#__PURE__*/function () {
261
    function Tooltip(element, config) {
262
      if (typeof Popper__default['default'] === 'undefined') {
263
        throw new TypeError('Bootstrap\'s tooltips require Popper (https://popper.js.org)');
264
      } // private
265
266
267
      this._isEnabled = true;
268
      this._timeout = 0;
269
      this._hoverState = '';
270
      this._activeTrigger = {};
271
      this._popper = null; // Protected
272
273
      this.element = element;
274
      this.config = this._getConfig(config);
275
      this.tip = null;
276
277
      this._setListeners();
278
    } // Getters
279
280
281
    var _proto = Tooltip.prototype;
282
283
    // Public
284
    _proto.enable = function enable() {
285
      this._isEnabled = true;
286
    };
287
288
    _proto.disable = function disable() {
289
      this._isEnabled = false;
290
    };
291
292
    _proto.toggleEnabled = function toggleEnabled() {
293
      this._isEnabled = !this._isEnabled;
294
    };
295
296
    _proto.toggle = function toggle(event) {
297
      if (!this._isEnabled) {
298
        return;
299
      }
300
301
      if (event) {
302
        var dataKey = this.constructor.DATA_KEY;
303
        var context = $__default['default'](event.currentTarget).data(dataKey);
304
305
        if (!context) {
306
          context = new this.constructor(event.currentTarget, this._getDelegateConfig());
307
          $__default['default'](event.currentTarget).data(dataKey, context);
308
        }
309
310
        context._activeTrigger.click = !context._activeTrigger.click;
311
312
        if (context._isWithActiveTrigger()) {
313
          context._enter(null, context);
314
        } else {
315
          context._leave(null, context);
316
        }
317
      } else {
318
        if ($__default['default'](this.getTipElement()).hasClass(CLASS_NAME_SHOW)) {
319
          this._leave(null, this);
320
321
          return;
322
        }
323
324
        this._enter(null, this);
325
      }
326
    };
327
328
    _proto.dispose = function dispose() {
329
      clearTimeout(this._timeout);
330
      $__default['default'].removeData(this.element, this.constructor.DATA_KEY);
331
      $__default['default'](this.element).off(this.constructor.EVENT_KEY);
332
      $__default['default'](this.element).closest('.modal').off('hide.bs.modal', this._hideModalHandler);
333
334
      if (this.tip) {
335
        $__default['default'](this.tip).remove();
336
      }
337
338
      this._isEnabled = null;
339
      this._timeout = null;
340
      this._hoverState = null;
341
      this._activeTrigger = null;
342
343
      if (this._popper) {
344
        this._popper.destroy();
345
      }
346
347
      this._popper = null;
348
      this.element = null;
349
      this.config = null;
350
      this.tip = null;
351
    };
352
353
    _proto.show = function show() {
354
      var _this = this;
355
356
      if ($__default['default'](this.element).css('display') === 'none') {
357
        throw new Error('Please use show on visible elements');
358
      }
359
360
      var showEvent = $__default['default'].Event(this.constructor.Event.SHOW);
361
362
      if (this.isWithContent() && this._isEnabled) {
363
        $__default['default'](this.element).trigger(showEvent);
364
        var shadowRoot = Util__default['default'].findShadowRoot(this.element);
365
        var isInTheDom = $__default['default'].contains(shadowRoot !== null ? shadowRoot : this.element.ownerDocument.documentElement, this.element);
366
367
        if (showEvent.isDefaultPrevented() || !isInTheDom) {
368
          return;
369
        }
370
371
        var tip = this.getTipElement();
372
        var tipId = Util__default['default'].getUID(this.constructor.NAME);
373
        tip.setAttribute('id', tipId);
374
        this.element.setAttribute('aria-describedby', tipId);
375
        this.setContent();
376
377
        if (this.config.animation) {
378
          $__default['default'](tip).addClass(CLASS_NAME_FADE);
379
        }
380
381
        var placement = typeof this.config.placement === 'function' ? this.config.placement.call(this, tip, this.element) : this.config.placement;
382
383
        var attachment = this._getAttachment(placement);
384
385
        this.addAttachmentClass(attachment);
386
387
        var container = this._getContainer();
388
389
        $__default['default'](tip).data(this.constructor.DATA_KEY, this);
390
391
        if (!$__default['default'].contains(this.element.ownerDocument.documentElement, this.tip)) {
392
          $__default['default'](tip).appendTo(container);
393
        }
394
395
        $__default['default'](this.element).trigger(this.constructor.Event.INSERTED);
396
        this._popper = new Popper__default['default'](this.element, tip, this._getPopperConfig(attachment));
397
        $__default['default'](tip).addClass(CLASS_NAME_SHOW);
398
        $__default['default'](tip).addClass(this.config.customClass); // If this is a touch-enabled device we add extra
399
        // empty mouseover listeners to the body's immediate children;
400
        // only needed because of broken event delegation on iOS
401
        // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
402
403
        if ('ontouchstart' in document.documentElement) {
404
          $__default['default'](document.body).children().on('mouseover', null, $__default['default'].noop);
405
        }
406
407
        var complete = function complete() {
408
          if (_this.config.animation) {
409
            _this._fixTransition();
410
          }
411
412
          var prevHoverState = _this._hoverState;
413
          _this._hoverState = null;
414
          $__default['default'](_this.element).trigger(_this.constructor.Event.SHOWN);
415
416
          if (prevHoverState === HOVER_STATE_OUT) {
417
            _this._leave(null, _this);
418
          }
419
        };
420
421
        if ($__default['default'](this.tip).hasClass(CLASS_NAME_FADE)) {
422
          var transitionDuration = Util__default['default'].getTransitionDurationFromElement(this.tip);
423
          $__default['default'](this.tip).one(Util__default['default'].TRANSITION_END, complete).emulateTransitionEnd(transitionDuration);
424
        } else {
425
          complete();
426
        }
427
      }
428
    };
429
430
    _proto.hide = function hide(callback) {
431
      var _this2 = this;
432
433
      var tip = this.getTipElement();
434
      var hideEvent = $__default['default'].Event(this.constructor.Event.HIDE);
435
436
      var complete = function complete() {
437
        if (_this2._hoverState !== HOVER_STATE_SHOW && tip.parentNode) {
438
          tip.parentNode.removeChild(tip);
439
        }
440
441
        _this2._cleanTipClass();
442
443
        _this2.element.removeAttribute('aria-describedby');
444
445
        $__default['default'](_this2.element).trigger(_this2.constructor.Event.HIDDEN);
446
447
        if (_this2._popper !== null) {
448
          _this2._popper.destroy();
449
        }
450
451
        if (callback) {
452
          callback();
453
        }
454
      };
455
456
      $__default['default'](this.element).trigger(hideEvent);
457
458
      if (hideEvent.isDefaultPrevented()) {
459
        return;
460
      }
461
462
      $__default['default'](tip).removeClass(CLASS_NAME_SHOW); // If this is a touch-enabled device we remove the extra
463
      // empty mouseover listeners we added for iOS support
464
465
      if ('ontouchstart' in document.documentElement) {
466
        $__default['default'](document.body).children().off('mouseover', null, $__default['default'].noop);
467
      }
468
469
      this._activeTrigger[TRIGGER_CLICK] = false;
470
      this._activeTrigger[TRIGGER_FOCUS] = false;
471
      this._activeTrigger[TRIGGER_HOVER] = false;
472
473
      if ($__default['default'](this.tip).hasClass(CLASS_NAME_FADE)) {
474
        var transitionDuration = Util__default['default'].getTransitionDurationFromElement(tip);
475
        $__default['default'](tip).one(Util__default['default'].TRANSITION_END, complete).emulateTransitionEnd(transitionDuration);
476
      } else {
477
        complete();
478
      }
479
480
      this._hoverState = '';
481
    };
482
483
    _proto.update = function update() {
484
      if (this._popper !== null) {
485
        this._popper.scheduleUpdate();
486
      }
487
    } // Protected
488
    ;
489
490
    _proto.isWithContent = function isWithContent() {
491
      return Boolean(this.getTitle());
492
    };
493
494
    _proto.addAttachmentClass = function addAttachmentClass(attachment) {
495
      $__default['default'](this.getTipElement()).addClass(CLASS_PREFIX + "-" + attachment);
496
    };
497
498
    _proto.getTipElement = function getTipElement() {
499
      this.tip = this.tip || $__default['default'](this.config.template)[0];
500
      return this.tip;
501
    };
502
503
    _proto.setContent = function setContent() {
504
      var tip = this.getTipElement();
505
      this.setElementContent($__default['default'](tip.querySelectorAll(SELECTOR_TOOLTIP_INNER)), this.getTitle());
506
      $__default['default'](tip).removeClass(CLASS_NAME_FADE + " " + CLASS_NAME_SHOW);
507
    };
508
509
    _proto.setElementContent = function setElementContent($element, content) {
510
      if (typeof content === 'object' && (content.nodeType || content.jquery)) {
511
        // Content is a DOM node or a jQuery
512
        if (this.config.html) {
513
          if (!$__default['default'](content).parent().is($element)) {
514
            $element.empty().append(content);
515
          }
516
        } else {
517
          $element.text($__default['default'](content).text());
518
        }
519
520
        return;
521
      }
522
523
      if (this.config.html) {
524
        if (this.config.sanitize) {
525
          content = sanitizeHtml(content, this.config.whiteList, this.config.sanitizeFn);
526
        }
527
528
        $element.html(content);
529
      } else {
530
        $element.text(content);
531
      }
532
    };
533
534
    _proto.getTitle = function getTitle() {
535
      var title = this.element.getAttribute('data-original-title');
536
537
      if (!title) {
538
        title = typeof this.config.title === 'function' ? this.config.title.call(this.element) : this.config.title;
539
      }
540
541
      return title;
542
    } // Private
543
    ;
544
545
    _proto._getPopperConfig = function _getPopperConfig(attachment) {
546
      var _this3 = this;
547
548
      var defaultBsConfig = {
549
        placement: attachment,
550
        modifiers: {
551
          offset: this._getOffset(),
552
          flip: {
553
            behavior: this.config.fallbackPlacement
554
          },
555
          arrow: {
556
            element: SELECTOR_ARROW
557
          },
558
          preventOverflow: {
559
            boundariesElement: this.config.boundary
560
          }
561
        },
562
        onCreate: function onCreate(data) {
563
          if (data.originalPlacement !== data.placement) {
564
            _this3._handlePopperPlacementChange(data);
565
          }
566
        },
567
        onUpdate: function onUpdate(data) {
568
          return _this3._handlePopperPlacementChange(data);
569
        }
570
      };
571
      return _extends({}, defaultBsConfig, this.config.popperConfig);
572
    };
573
574
    _proto._getOffset = function _getOffset() {
575
      var _this4 = this;
576
577
      var offset = {};
578
579
      if (typeof this.config.offset === 'function') {
580
        offset.fn = function (data) {
581
          data.offsets = _extends({}, data.offsets, _this4.config.offset(data.offsets, _this4.element) || {});
582
          return data;
583
        };
584
      } else {
585
        offset.offset = this.config.offset;
586
      }
587
588
      return offset;
589
    };
590
591
    _proto._getContainer = function _getContainer() {
592
      if (this.config.container === false) {
593
        return document.body;
594
      }
595
596
      if (Util__default['default'].isElement(this.config.container)) {
597
        return $__default['default'](this.config.container);
598
      }
599
600
      return $__default['default'](document).find(this.config.container);
601
    };
602
603
    _proto._getAttachment = function _getAttachment(placement) {
604
      return AttachmentMap[placement.toUpperCase()];
605
    };
606
607
    _proto._setListeners = function _setListeners() {
608
      var _this5 = this;
609
610
      var triggers = this.config.trigger.split(' ');
611
      triggers.forEach(function (trigger) {
612
        if (trigger === 'click') {
613
          $__default['default'](_this5.element).on(_this5.constructor.Event.CLICK, _this5.config.selector, function (event) {
614
            return _this5.toggle(event);
615
          });
616
        } else if (trigger !== TRIGGER_MANUAL) {
617
          var eventIn = trigger === TRIGGER_HOVER ? _this5.constructor.Event.MOUSEENTER : _this5.constructor.Event.FOCUSIN;
618
          var eventOut = trigger === TRIGGER_HOVER ? _this5.constructor.Event.MOUSELEAVE : _this5.constructor.Event.FOCUSOUT;
619
          $__default['default'](_this5.element).on(eventIn, _this5.config.selector, function (event) {
620
            return _this5._enter(event);
621
          }).on(eventOut, _this5.config.selector, function (event) {
622
            return _this5._leave(event);
623
          });
624
        }
625
      });
626
627
      this._hideModalHandler = function () {
628
        if (_this5.element) {
629
          _this5.hide();
630
        }
631
      };
632
633
      $__default['default'](this.element).closest('.modal').on('hide.bs.modal', this._hideModalHandler);
634
635
      if (this.config.selector) {
636
        this.config = _extends({}, this.config, {
637
          trigger: 'manual',
638
          selector: ''
639
        });
640
      } else {
641
        this._fixTitle();
642
      }
643
    };
644
645
    _proto._fixTitle = function _fixTitle() {
646
      var titleType = typeof this.element.getAttribute('data-original-title');
647
648
      if (this.element.getAttribute('title') || titleType !== 'string') {
649
        this.element.setAttribute('data-original-title', this.element.getAttribute('title') || '');
650
        this.element.setAttribute('title', '');
651
      }
652
    };
653
654
    _proto._enter = function _enter(event, context) {
655
      var dataKey = this.constructor.DATA_KEY;
656
      context = context || $__default['default'](event.currentTarget).data(dataKey);
657
658
      if (!context) {
659
        context = new this.constructor(event.currentTarget, this._getDelegateConfig());
660
        $__default['default'](event.currentTarget).data(dataKey, context);
661
      }
662
663
      if (event) {
664
        context._activeTrigger[event.type === 'focusin' ? TRIGGER_FOCUS : TRIGGER_HOVER] = true;
665
      }
666
667
      if ($__default['default'](context.getTipElement()).hasClass(CLASS_NAME_SHOW) || context._hoverState === HOVER_STATE_SHOW) {
668
        context._hoverState = HOVER_STATE_SHOW;
669
        return;
670
      }
671
672
      clearTimeout(context._timeout);
673
      context._hoverState = HOVER_STATE_SHOW;
674
675
      if (!context.config.delay || !context.config.delay.show) {
676
        context.show();
677
        return;
678
      }
679
680
      context._timeout = setTimeout(function () {
681
        if (context._hoverState === HOVER_STATE_SHOW) {
682
          context.show();
683
        }
684
      }, context.config.delay.show);
685
    };
686
687
    _proto._leave = function _leave(event, context) {
688
      var dataKey = this.constructor.DATA_KEY;
689
      context = context || $__default['default'](event.currentTarget).data(dataKey);
690
691
      if (!context) {
692
        context = new this.constructor(event.currentTarget, this._getDelegateConfig());
693
        $__default['default'](event.currentTarget).data(dataKey, context);
694
      }
695
696
      if (event) {
697
        context._activeTrigger[event.type === 'focusout' ? TRIGGER_FOCUS : TRIGGER_HOVER] = false;
698
      }
699
700
      if (context._isWithActiveTrigger()) {
701
        return;
702
      }
703
704
      clearTimeout(context._timeout);
705
      context._hoverState = HOVER_STATE_OUT;
706
707
      if (!context.config.delay || !context.config.delay.hide) {
708
        context.hide();
709
        return;
710
      }
711
712
      context._timeout = setTimeout(function () {
713
        if (context._hoverState === HOVER_STATE_OUT) {
714
          context.hide();
715
        }
716
      }, context.config.delay.hide);
717
    };
718
719
    _proto._isWithActiveTrigger = function _isWithActiveTrigger() {
720
      for (var trigger in this._activeTrigger) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
721
        if (this._activeTrigger[trigger]) {
722
          return true;
723
        }
724
      }
725
726
      return false;
727
    };
728
729
    _proto._getConfig = function _getConfig(config) {
730
      var dataAttributes = $__default['default'](this.element).data();
731
      Object.keys(dataAttributes).forEach(function (dataAttr) {
732
        if (DISALLOWED_ATTRIBUTES.indexOf(dataAttr) !== -1) {
733
          delete dataAttributes[dataAttr];
734
        }
735
      });
736
      config = _extends({}, this.constructor.Default, dataAttributes, typeof config === 'object' && config ? config : {});
737
738
      if (typeof config.delay === 'number') {
739
        config.delay = {
740
          show: config.delay,
741
          hide: config.delay
742
        };
743
      }
744
745
      if (typeof config.title === 'number') {
746
        config.title = config.title.toString();
747
      }
748
749
      if (typeof config.content === 'number') {
750
        config.content = config.content.toString();
751
      }
752
753
      Util__default['default'].typeCheckConfig(NAME, config, this.constructor.DefaultType);
754
755
      if (config.sanitize) {
756
        config.template = sanitizeHtml(config.template, config.whiteList, config.sanitizeFn);
757
      }
758
759
      return config;
760
    };
761
762
    _proto._getDelegateConfig = function _getDelegateConfig() {
763
      var config = {};
764
765
      if (this.config) {
766
        for (var key in this.config) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
767
          if (this.constructor.Default[key] !== this.config[key]) {
768
            config[key] = this.config[key];
769
          }
770
        }
771
      }
772
773
      return config;
774
    };
775
776
    _proto._cleanTipClass = function _cleanTipClass() {
777
      var $tip = $__default['default'](this.getTipElement());
778
      var tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX);
779
780
      if (tabClass !== null && tabClass.length) {
781
        $tip.removeClass(tabClass.join(''));
782
      }
783
    };
784
785
    _proto._handlePopperPlacementChange = function _handlePopperPlacementChange(popperData) {
786
      this.tip = popperData.instance.popper;
787
788
      this._cleanTipClass();
789
790
      this.addAttachmentClass(this._getAttachment(popperData.placement));
791
    };
792
793
    _proto._fixTransition = function _fixTransition() {
794
      var tip = this.getTipElement();
795
      var initConfigAnimation = this.config.animation;
796
797
      if (tip.getAttribute('x-placement') !== null) {
798
        return;
799
      }
800
801
      $__default['default'](tip).removeClass(CLASS_NAME_FADE);
802
      this.config.animation = false;
803
      this.hide();
804
      this.show();
805
      this.config.animation = initConfigAnimation;
806
    } // Static
807
    ;
808
809
    Tooltip._jQueryInterface = function _jQueryInterface(config) {
810
      return this.each(function () {
811
        var $element = $__default['default'](this);
812
        var data = $element.data(DATA_KEY);
813
814
        var _config = typeof config === 'object' && config;
815
816
        if (!data && /dispose|hide/.test(config)) {
817
          return;
818
        }
819
820
        if (!data) {
821
          data = new Tooltip(this, _config);
822
          $element.data(DATA_KEY, data);
823
        }
824
825
        if (typeof config === 'string') {
826
          if (typeof data[config] === 'undefined') {
827
            throw new TypeError("No method named \"" + config + "\"");
828
          }
829
830
          data[config]();
831
        }
832
      });
833
    };
834
835
    _createClass(Tooltip, null, [{
836
      key: "VERSION",
837
      get: function get() {
838
        return VERSION;
839
      }
840
    }, {
841
      key: "Default",
842
      get: function get() {
843
        return Default;
844
      }
845
    }, {
846
      key: "NAME",
847
      get: function get() {
848
        return NAME;
849
      }
850
    }, {
851
      key: "DATA_KEY",
852
      get: function get() {
853
        return DATA_KEY;
854
      }
855
    }, {
856
      key: "Event",
857
      get: function get() {
858
        return Event;
859
      }
860
    }, {
861
      key: "EVENT_KEY",
862
      get: function get() {
863
        return EVENT_KEY;
864
      }
865
    }, {
866
      key: "DefaultType",
867
      get: function get() {
868
        return DefaultType;
869
      }
870
    }]);
871
872
    return Tooltip;
873
  }();
874
  /**
875
   * ------------------------------------------------------------------------
876
   * jQuery
877
   * ------------------------------------------------------------------------
878
   */
879
880
881
  $__default['default'].fn[NAME] = Tooltip._jQueryInterface;
882
  $__default['default'].fn[NAME].Constructor = Tooltip;
883
884
  $__default['default'].fn[NAME].noConflict = function () {
885
    $__default['default'].fn[NAME] = JQUERY_NO_CONFLICT;
886
    return Tooltip._jQueryInterface;
887
  };
888
889
  return Tooltip;
890
891
})));
892
//# sourceMappingURL=tooltip.js.map
893